﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using DONGACS.Common;
using DONGACS.DAO.Base;
using DONGACS.Domain;

namespace DONGACS.DAO
{
    public class DepartmentsDao : BaseDao<Departments>
    {
        //lấy tất cả Departments
        //public IList<Departments> GetAllDepartments()
        //{
        //    CommandText = "Select * From TB_Departments P Where P.IsDelete = 0";
        //    Commandtype = CommandType.Text;

        //    DataTable table = GetDataTable();

        //    IList<Departments> list = CollectionHelper.ConvertTo<Departments>(table);
        //    return list;
        //}


        //Lấy Departments theo ID
        public Departments GetDepartmentsById( string id)
        {
            CommandText = "Select * From TB_Departments P Where P.ID = " + id + " and P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            Departments departments = table.Rows.Count != 0 ? CollectionHelper.CreateItem<Departments>(table.Rows[0]) : null;

            return departments;
        }

        public Departments GetDepartmentByName(string departmentName)
        {
            CommandText = "Select * From TB_Departments P Where P.DepartmentName = N'" + departmentName + "' and P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            Departments departments = table.Rows.Count != 0 ? CollectionHelper.CreateItem<Departments>(table.Rows[0]) : null;

            return departments;
        }

        public bool AddNewDepartments(Departments departments)
        {
            return Insert("TB_Departments", departments);
        }
        
        public bool AddNewDepartments(Departments departments, ref int idReturn)
        {
            return Insert("TB_Departments", departments, ref idReturn);
        }

        public bool Update(Departments departments)
        {
            return Update("TB_Departments", departments);
        }

        public bool ShiftDelete(string id)
        {
            return this.ShiftDelete<Departments>("TB_Departments", id);
        }

        public bool Delete(string id)
        {
            return this.Delete<Departments>("TB_Departments", id);
        }
    }
}
